//
//  WordHotTabelHeaderView.m
//  MyProject
//
//  Created by dllo on 15/10/31.
//  Copyright (c) 2015年 蓝鸥0825. All rights reserved.
//

#import "WordHotTabelHeaderView.h"
#import "WordHotTabelHeaderCollectionViewCell.h"
#import "UIImageView+WebCache.h"



#import "FoodViewController.h"
#import "ActivityViewController.h"


#define WIDTH self.frame.size.width

@implementation WordHotTabelHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createCollectionView];
        [self createScollView];
    }
    return self;
}

#pragma mark - createScollView

- (void)createScollView{
    
    self.wordHotHeaderTabelScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.frame.size.height / 100 * 50, WIDTH, self.frame.size.height /100 * 50)];
    [self addSubview:self.wordHotHeaderTabelScrollView];
    self.wordHotHeaderTabelScrollView.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1];
    self.wordHotHeaderTabelScrollView.contentSize = CGSizeMake(self.frame.size.width  * self.arrayWordHotHeaderTabelScrollView.count, 0);
    self.wordHotHeaderTabelScrollView.pagingEnabled = YES;
    
    NSLog(@"%@", self.arrayWordHotHeaderTabelScrollView );
    
    for (NSInteger i = 0; i < self.arrayWordHotHeaderTabelScrollView.count; i++) {
        
        UIImageView *image = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 6 + WIDTH * i, self.frame.size.height /100 * 3,WIDTH / 3 * 2, self.frame.size.height / 100 * 44)];
        [self.wordHotHeaderTabelScrollView addSubview:image];
        [image sd_setImageWithURL:[NSURL URLWithString:self.arrayWordHotHeaderTabelScrollView[i][@"img"]]];
        
    }
    
    
    
    
    
    
}

- (void)setArrayWordHotHeaderTabelScrollView:(NSMutableArray *)arrayWordHotHeaderTabelScrollView
{
    _arrayWordHotHeaderTabelScrollView = arrayWordHotHeaderTabelScrollView;
    [self createScollView];
}


#pragma mark - createCollectionView
- (void)createCollectionView{
    
    self.wordHotHeaderTabelCollectionLayout = [[UICollectionViewFlowLayout alloc] init];
    self.wordHotHeaderTabelCollectionLayout.itemSize = CGSizeMake(self.frame.size.width /100 * 20, self.frame.size.height /100 * 38);
    self.wordHotHeaderTabelCollectionLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.wordHotHeaderTabelCollectionLayout.sectionInset = UIEdgeInsetsMake(self.frame.size.height / 100, self.frame.size.width / 100 * 3, self.frame.size.height / 100, self.frame.size.width / 100);
    self.wordHotHeaderTabelCollectionLayout.minimumLineSpacing = self.frame.size.width / 100 * 4;
    
    
    self.wordHotHeaderTabelCollection = [[UICollectionView alloc]initWithFrame:CGRectMake(self.frame.size.width / 100, self.frame.size.height / 100 * 2, self.frame.size.width /100 * 98, self.frame.size.height /100 * 45) collectionViewLayout:self.wordHotHeaderTabelCollectionLayout];
    self.wordHotHeaderTabelCollection.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.wordHotHeaderTabelCollection];
    self.wordHotHeaderTabelCollection.dataSource = self;
    self.wordHotHeaderTabelCollection.delegate = self;
    [self.wordHotHeaderTabelCollection registerClass:[WordHotTabelHeaderCollectionViewCell class] forCellWithReuseIdentifier: @"reuse"];
    

    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.arrayWordHotHeaderTabelCollection.count;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    WordHotTabelHeaderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuse" forIndexPath:indexPath];
    cell.modelCollectionWordHotHeader = self.arrayWordHotHeaderTabelCollection[indexPath.row];
    return cell;
    
}


- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 0){
        
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=20&order=new&page=1&from=0";
    }
    
    
    else if (indexPath.row == 1){
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=21&order=new&page=1&from=0";
        
    }
    else if(indexPath.row == 2){
        
        FoodViewController *foodVC = [[FoodViewController alloc] init];
        [self.VC.navigationController pushViewController:foodVC animated:YES];
        foodVC.str = @"http://api.meishi.cc/v5/topic_list2.php?format=jsonlat=&lon=&source=iphone&format=json&gid=22&order=new&page=1&from=0";
        
    }
    else{
        
        ActivityViewController *acVC = [[ActivityViewController alloc] init];
        [self.VC.navigationController pushViewController:acVC animated:YES];
    }
    
    
    
}




@end
